from selenium import webdriver
from selenium.webdriver.common.by import By

from exam.page.base_page import BasePage
from exam.page.main_page import MainPage


class LoginPage(BasePage):
    __USERNAME = By.XPATH, "//*[@class='form-control gl-form-input js-username-field']"
    __PASSWORD = By.XPATH, "//*[@ID='user_password']"
    __LOGIN_BUTTON = By.XPATH, "//*[@class='gl-button btn btn-block btn-md btn-confirm js-sign-in-button']"

    def goto_main_page(self):
        self.open_url("https://contest.gitlab.ceba.ceshiren.com/users/sign_in")
        self.find_ele_and_sendkeys(*self.__USERNAME, "1464233801@qq.com")
        self.find_ele_and_sendkeys(*self.__PASSWORD, "Hogwarts2024")
        self.find_ele_and_click(*self.__LOGIN_BUTTON)
        return MainPage(self.driver)

    def quit(self):
        self.close_win()
